 #define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
	string compressString(string S)
	{
		string ans;
		int i = 0, j = 0;
		while (i < S.size())
		{
			while (j < S.size() && S[j] == S[i])
				j++;
			ans += S[i];
			ans += to_string(j - i);
			i = j;
		}
		return ans.size() < S.size() ? ans : S;
	}
};